package com.ruoyi.api.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SpDuizhao;
import com.ruoyi.system.service.ISpDuizhaoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 测评对照Controller
 * 
 * @author ruoyi
 * @date 2022-11-21
 */
@RestController
@RequestMapping("/api/duizhao")
public class SpDuizhaoApiController extends BaseController
{
    @Autowired
    private ISpDuizhaoService spDuizhaoService;

    /**
     * 查询测评对照列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SpDuizhao spDuizhao)
    {
        startPage();
        List<SpDuizhao> list = spDuizhaoService.selectSpDuizhaoListWeb(spDuizhao);
        return getDataTable(list);
    }

    /**
     * 导出测评对照列表
     */
    @Log(title = "测评对照", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SpDuizhao spDuizhao)
    {
        List<SpDuizhao> list = spDuizhaoService.selectSpDuizhaoListWeb(spDuizhao);
        ExcelUtil<SpDuizhao> util = new ExcelUtil<SpDuizhao>(SpDuizhao.class);
        util.exportExcel(response, list, "测评对照数据");
    }

    /**
     * 获取测评对照详细信息
     */
    @GetMapping(value = "/{dzId}")
    public AjaxResult getInfo(@PathVariable("dzId") Long dzId)
    {
        return AjaxResult.success(spDuizhaoService.selectSpDuizhaoByDzId(dzId));
    }

    /**
     * 新增测评对照
     */
    @Log(title = "测评对照", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SpDuizhao spDuizhao)
    {
        return toAjax(spDuizhaoService.insertSpDuizhao(spDuizhao));
    }

    /**
     * 修改测评对照
     */
    @Log(title = "测评对照", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SpDuizhao spDuizhao)
    {
        return toAjax(spDuizhaoService.updateSpDuizhao(spDuizhao));
    }

    /**
     * 删除测评对照
     */
    @Log(title = "测评对照", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dzIds}")
    public AjaxResult remove(@PathVariable Long[] dzIds)
    {
        return toAjax(spDuizhaoService.deleteSpDuizhaoByDzIds(dzIds));
    }
}
